package sundun.sharding.scaner;


import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.MethodParameter;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * @author zxl
 * @Description:
 * @date 2025/2/6 12:44
 */
@Slf4j
@Getter
@Setter
public class Invoker {
    /**
     * 目标查询方法
     */
    private Method method;

    /**
     * 目标对象
     */
    private Object target;


    /**
     * 执行方法标识
     */
    private String mark;

    /**
     * 参数
     */
    private MethodParameter[] parameters;



    public Invoker() {

    }


    public static Invoker valueOf(String mark,Method method, Object target) {
        Invoker invoker = new Invoker();
        invoker.mark = mark;
        invoker.method = method;
        invoker.target = target;
        return invoker;
    }

    public static Invoker valueOf(Method method, Method insertMethod, Object target) {
        Invoker invoker = new Invoker();
        invoker.method = method;
        invoker.target = target;

        return invoker;
    }

    public Object invoke(Object... args) throws InvocationTargetException, IllegalAccessException {
        return method.invoke(target, args);
    }

}
